import java.util.Scanner;

public class test7 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); // 数组个数
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        System.out.println(maxProfit(nums));
    }

    public static int maxProfit(int[] prices) {
        // 一边找最低售价的那一天,一边找最高价
        int min = prices[0];
        int max = 0;
        for (int i = 1; i < prices.length; i++) {
            if(min>prices[i])
                min = prices[i];
            if(prices[i]-min>max)
                max = prices[i]-min;
        }
        return max;
    }
}
